<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowd');

class User {

    var $CI = '';
    var $user = 0;
    var $loged = false;

    function __construct($par=array()) {
        if ($par && count($par) > 0) {
            $this->initialize($par);
        }

        $this->CI = & get_instance();

        $this->user = $this->CI->session->userdata('user');

        if ($this->user) {
            foreach ($this->user as $i => $v) {
                $this->$i = $v;
            }
            $this->loged = true;
        }
    }

    function initialize($par) {
        foreach ($par as $i => $v) {
            $this->$i = $v;
        }
    }
    
    function auth(){
        if (!$this->loged) {
            header('Location: ' . BASE_URL . 'home/');
            exit();
        }
    }

    function get($index) {
        return $this->$index;
    }
}

